package com.tangding.net.tcp;

import org.springframework.stereotype.Component;

import com.tangding.common.holder.SpringContextHolder;

import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageCodec;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年3月15日_下午3:41:09
 *
 */
@Component
public class GameServerChannelInitializer extends ChannelInitializer<SocketChannel>{
	
	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ch.pipeline()
//		.addLast("IdleStateHandler", new IdleStateHandler(60, 60, 0))//设置idle
		.addLast(getCoder(), getHandler())
		;
	}
	
	private ByteToMessageCodec<byte[]> getCoder() {
		return SpringContextHolder.getBean("gameCoder");
	}
	
	private ChannelInboundHandlerAdapter getHandler() {
		return SpringContextHolder.getBean("gameServerHandler");
	}
}